﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Model;
using Ecreate.Business;

namespace Ecreate.Web.pages
{
    public partial class product : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData("-1");
        }

        private void BindData(string parentclassid)
        {
            ProductClassService s = new ProductClassService();
            IList l = s.getProductClassByParentID(parentclassid);
            dl_class1.DataSource = l;
            dl_class1.DataBind();
        }

        protected void dl_class1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ProductClass pclass = e.Item.DataItem as ProductClass;
                ProductClassService s = new ProductClassService();
                IList l = s.getProductClassByParentID(pclass.Classid);
                DataList dl_class2 = e.Item.FindControl("dl_class2") as DataList;
                dl_class2.DataSource = l;
                dl_class2.DataBind();
            }
        }

        protected void dl_class2_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ProductService service = new ProductService();
                Product model = new Product();
                ProductClass pclass = e.Item.DataItem as ProductClass;
                model.Classid = pclass.Classid;
                ArrayList l = service.getProductByClassID(model);
                DataList dl_product = e.Item.FindControl("dl_product") as DataList;
                dl_product.DataSource = l;
                dl_product.DataBind();
            }
        }
    }
}
